/*团队日志
彭济
9-23*/
import Sequelize from 'sequelize'
import sequelize from './../../database'

const Teamlog = sequelize.define('sys_teamlog',{
	id:{
		type: Sequelize.UUIDV4,
        defaultValue: Sequelize.UUIDV4,
        unique: true,
        allowNull: false,
        primaryKey:true
	},
	diary_title:{
		type: Sequelize.STRING,
        allowNull:false
	},
	diary_subtitle:{
		type: Sequelize.STRING,
        allowNull:true
	},
	type:{
		type: Sequelize.STRING,
        allowNull:false
	},
	author:{
		type: Sequelize.STRING,
        allowNull:false
	},
	content:{
		type: Sequelize.STRING,
        allowNull:false
	},
	is_publish:{
		type: Sequelize.INTEGER,
		allowNull:false,
		defaultValue:1,
	}
},{
	tableName:'sys_teamlog',
	freezeTableName:false,
	updatedAt:'updated_at',
    createdAt:'created_at',
});

class TeamlogModel{
	insertLog(record){
		return Teamlog.create(record);
	}
	delLogById(id){
		return Teamlog.destroy({
			where:{
				id:id
			}
		});
	}
	findListPublish(){
        return Teamlog.findAll({
            where:{
                is_publist:1
            }
        })
    }
	logFindById(id){
		return Teamlog.findById(id);
	}
	logFindAll(){
		return Teamlog.findAll();
	}
	//分页
	logPaging(record){
		return Teamlog.findAndCount({
            limit:record.page_size,
            offset: record.page_size * (record.page_no -1)
        })
	}
	logUpdateById(record){
		return Teamlog.update(record,{
			where:{
				id:record.id
			},
			fields:['diary_title','diary_subtitle','type','author','content','is_publish']
		});
	}
}
module.exports = new TeamlogModel();